package com.wzl.time;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;

/**
 * @author weiZhiLin
 * @version 1.0
 * @date 2020/1/7 9:28
 */
public class Main {
    public static void main(String[] args) {
        // ArrayList 数组扩容
        //  System.arraycopy();

        // 获取当前时间
        System.out.println("获取当前时间");
        LocalDateTime time = LocalDateTime.now();
        System.out.println(time);
        System.out.println(time.getMonth());

        // 构造一个日期
        System.out.println("构造一个日期");
        LocalDateTime createTime = LocalDateTime.of(2021, Month.SEPTEMBER, 21, 21, 59);
        System.out.println(createTime);

        // 修改日期
        System.out.println("修改日期");
        System.out.println(createTime.minusDays(1));
        System.out.println(createTime.plusMonths(1));

        // 格式化日期
        System.out.println("格式化日期");
        System.out.println(createTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
        System.out.println(createTime.format(DateTimeFormatter.BASIC_ISO_DATE));
        System.out.println(createTime.format(DateTimeFormatter.ISO_TIME));

        // 字符串解析
        String timeStr = "2020年02-02 12:12:00";
        System.out.println(LocalDateTime.parse(timeStr,DateTimeFormatter.ofPattern("yyyy年MM-dd HH:mm:ss")));
        String timeStr2 = "2020-02-02";
        System.out.println(LocalDate.parse(timeStr2));
        String timeStr3 = "2020年02-02";
        System.out.println(LocalDate.parse(timeStr3,DateTimeFormatter.ofPattern("yyyy年MM-dd")));

    }
}
